package com.qingneng.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.qingneng.service.sdk.IProjectInfoService;
import com.qingneng.service.sdk.IWorkBudgetService;
import com.qingneng.vo.BudgetFeeDoInfo;
import com.qingneng.vo.BudgetWorkDoInfo;
import com.qingneng.vo.ProjectInfo;
import com.qingneng.vo.ProjectWorkInfo;
import com.tbfs.common.BaseAction;

public class BudgetSheetAction extends BaseAction{
	private static Logger logger = Logger.getLogger(BudgetSheetAction.class);
	private ProjectInfo projectInfo;
	
	private List list ;
	
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}

	private IProjectInfoService projectInfoService;
	private IWorkBudgetService workBudgetService;
	
	public ProjectInfo getProjectInfo() {
		return projectInfo;
	}
	public void setProjectInfo(ProjectInfo projectInfo) {
		this.projectInfo = projectInfo;
	}
	
	
	public BudgetSheetAction(){
		
	}
	public BudgetSheetAction(IProjectInfoService projectInfoService,IWorkBudgetService workBudgetService ){
		this.projectInfoService = projectInfoService;
		this.workBudgetService = workBudgetService;
	}
	
	public String execute(){
		logger.info("+++BudgetSheetAction begin execute+++");
		try {
			//根据id查询 项目信息
			 List projectInfoList  = projectInfoService.getProjectInfo(projectInfo);
			 if(projectInfoList!=null && projectInfoList.size()>0){
				 projectInfo =  (ProjectInfo )projectInfoList.get(0);
			 }
			 // 工程信息
			 List<ProjectWorkInfo> projectWorkInfo = projectInfoService.getProjectWorkInfo(projectInfo.getId());
			 Map infoMap = null;
			 list = new ArrayList();
			 if(projectWorkInfo!=null && projectWorkInfo.size()>0){
				 BudgetWorkDoInfo para  = null;
				 for(Iterator<ProjectWorkInfo> iter = projectWorkInfo.iterator();iter.hasNext();){
					 infoMap = new HashMap();
					 ProjectWorkInfo  bean = iter.next();
					 int project_workinfo_id = bean.getId();
					 para = new BudgetWorkDoInfo();
					 para.setProject_workinfo_id(project_workinfo_id);
					 para.setParent_item_id(0);
					 //预算信息
					 List workDoInfo = workBudgetService.getWorkDoInfoByWorkInfoIdAndItemId(para);
					 infoMap.put("no", bean.getCesspoolNo());
					 infoMap.put("info", workDoInfo);
					 
					 
					 //取费信息
					 BudgetFeeDoInfo fee = new BudgetFeeDoInfo();
					 fee.setProject_workinfo_id(project_workinfo_id);
					 List feeInfo = workBudgetService.getBudgetFeeDoInfo(fee);
					 infoMap.put("feeinfo", feeInfo);
					 
					 list.add(infoMap);
					 
					 
				 }
			 }
			 
			 
			 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Action.SUCCESS;
	}

}
